package com.edushare.common.dao;

import java.util.HashMap;
import java.util.List;

import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.query.SelectQuery;

import com.edushare.common.orm.ORMInterface;
import com.edushare.common.vo.OutgoingEmails;

public class OutgoingEmailsDAO extends CayenneBasedDAO {

	public OutgoingEmailsDAO(ORMInterface ormInterface) {
		super(ormInterface);
	}
	
	@SuppressWarnings("unchecked")
	public List<OutgoingEmails> getPendingEmails(){
		Expression exp = Expression.fromString("status = $status");
		HashMap<String,Integer> params = new HashMap<String,Integer>();
		params.put("status", OutgoingEmails.EMAIL_TO_BE_SENT);
		SelectQuery query = new SelectQuery(OutgoingEmails.class, exp.expWithParameters(params));
		List<OutgoingEmails> lst = getDataContext().performQuery(query);
		return lst;
	}
	
	public void sendMail(OutgoingEmails mail){
		getDataContext().registerNewObject(mail);
		getDataContext().commitChanges();
	}

}
